require.config({
    paths:{
        'backbone':'./libs/backbone',
        'underscore':'./libs/underscore',
        'jquery':'./libs/jquery',
        'text':'./libs/text',
        'css':'./libs/css',
        "math":"./libs/math",
        "homejs":"./home/js/home",
        "homejx":"./home/js/homejx",
        "shanjs":"./shan/js/shan",
        "shanjx":"./shan/js/shanjx",
        "shopcarjs":"./shopcar/js/shopcar",
        'jweixin-1.0.0':'./libs/jweixin-1.0.0', // 微信jssdk
        'qqMap':'./libs/qqMapjs', // 腾讯地图模块
        'cookie':'./libs/cookie'
    }
});
require(['backbone'],function (Backbone) {
    var Router = Backbone.Router.extend({
        routes:{
            '':'home',
            'home':'home',
            'mine':'mine',
            'shan':'shan',
            'shopcar':'shopcar',
            'fail':'fail',
            'login':'login'
        },
        home:function () {
            require(['jquery','text!./home/home.html','homejs','homejx','jweixin-1.0.0', 'finger','cookie','qqMap','css!./home/css/home.css','css!./libs/reset.css'],function ($,html,homejs,homejx, wx, finger,cookie) {
                $('.content').html(html);
                homejx.jx();
                homejs.sum();
                var date = new Date();
                var time = parseInt(date.getTime()/1000);


                console.log(time);
                // 签名部分交给服务器做，前端不要做！！
                var signature = finger.getFinger(time);
                console.log(signature);
                // 设置jssdk接口参数
                wx.config({
                    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: 'wxbc2938b0a48f43b4', // 必填，公众号的唯一标识
                    timestamp: time, // 必填，生成签名的时间戳
                    nonceStr: 'abc', // 必填，生成签名的随机串
                    signature: signature,// 必填，签名，见附录1
                    jsApiList: ['getLocation', 'openLocation','scanQRCode'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                  });

                var latitude = 0,
                    longitude = 0,
                    speed = 0,
                    accuracy = 0;

                wx.ready(function(){
                  $('.sao').click(function(){
                    wx.scanQRCode({
                      needResult: 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                      scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                      success: function (res) {
                        var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                      }
                    });

                  });

                  $('#add').click(function(){
                        wx.getLocation({
                            type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                            success: function(res){
                                latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                                longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                                speed = res.speed; // 速度，以米/每秒计
                                accuracy = res.accuracy; // 位置精度
                                geocoder = new qq.maps.Geocoder({
                                    complete:function(result){
                                          alert('成功：'+result.detail.addressComponents.city + result.detail.addressComponents.street);
                                          var address;
                                          address = (result.detail.addressComponents.city + result.detail.addressComponents.street);
                                          $('#add').text(address);
                                     }
                                })
                                var coord=new qq.maps.LatLng(latitude,longitude);
                                geocoder.getAddress(coord);
                            }
                        })
                    })

                })
              var tel = 'tel';
              var psd = 'psd';
              var telz = cookie.getCookie('tel');
              var psdz = cookie.getCookie('psd');
              //    1111111111111111      22222222222222222222;
              if(telz != '' && psdz != ''){
                $('.shop').attr('href','#shopcar');
                $('.me').attr('href','#mine');
              }else {
                $('.shop').attr('href','#fail');
                $('.me').attr('href','#login');
              }

              })
        },
        mine:function () {
            require(['jquery','text!./mine/mine.html','cookie','css!./mine/css/mine.css','css!./libs/reset.css'],function ($,html,cookie) {
                $('.content').html(html);
                $('.tuichu').click(function(){
                  $('.shop').attr('href','#fail');
                  $('.me').attr('href','#login');
                  cookie.setCookie('tel', "", -1);
                  cookie.setCookie('psd', "", -1);
                  window.location.replace('./index.html#login')
                })

            })
        },
        shan:function () {
            require(['jquery','text!./shan/shan.html','shanjs','shanjx','cookie','css!./shan/css/shan.css','css!./libs/reset.css'],function ($,html,shanjs,shanjx,cookie) {
                $('.content').html(html);
                shanjx.jx1();
                shanjs.tab();
                var telz = cookie.getCookie('tel');
                var psdz = cookie.getCookie('psd');
                if(telz != '' && psdz != ''){
                  $('.shop').attr('href','#shopcar');
                  $('.me').attr('href','#mine');
                }else {
                  $('.shop').attr('href','#fail');
                  $('.me').attr('href','#login');
                }
            })
        },
        shopcar:function () {
            require(['jquery','text!./shopcar/shopcar.html','shopcarjs','css!./shopcar/css/shopcar.css','css!./libs/reset.css'],function ($,html,shopcarjs) {
                $('.content').html(html);
                shopcarjs.jx2();
            })
        },
        fail:function () {
            require(['jquery','text!./fail/fail.html','cookie','css!./fail/css/fail.css','css!./libs/reset.css'],function ($,html,cookie) {
                $('.content').html(html);
                var telz = cookie.getCookie('tel');
                var psdz = cookie.getCookie('psd');
                if(telz != '' && psdz != ''){
                  $('.shop').attr('href','#shopcar');
                  $('.me').attr('href','#mine');
                }else {
                  $('.shop').attr('href','#fail');
                  $('.me').attr('href','#login');
                }
            })
        },
        login:function () {
            require(['jquery','text!./login/login.html','cookie','css!./login/css/login.css','css!./libs/reset.css'],function ($,html,cookie) {
                $('.content').html(html);
                var $tel = $('#telNumber');
                var oDate = new Date();
                var $yzm = $('#yzm');
                var $btn = $('#btn');
                var tel = 'tel';
                var psd = 'psd';
                var telz = cookie.getCookie('tel');
                var psdz = cookie.getCookie('psd');
                if(telz != '' && psdz != ''){
                  $('.shop').attr('href','#shopcar');
                  $('.me').attr('href','#mine');
                }else {
                  $('.shop').attr('href','#fail');
                  $('.me').attr('href','#login');
                }
                $btn.click(function(){
                    cookie.setCookie(tel,$tel.val(),30);
                    cookie.setCookie(psd,$yzm.val(),30);
                    $('.shop').attr('href','#shopcar');
                    $('.me').attr('href','#mine');
                    if($tel.val() == '' || $yzm.val() == ''){
                      console.log('应户名密码不能为空');
                    }else{
                      window.location.replace('./index.html#mine')
                    }
                })

            })
        }
    });
    //启动路由
    var router = new Router();
    //路由监听
    Backbone.history.start();
})
